<?php
date_default_timezone_set('America/Chicago');

spl_autoload_register(function($className) {
	$fileName = __DIR__ . '/source/' . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
	if(file_exists($fileName)) {
		include $fileName;
		return true;
	}
	return false;
});

use Skyline\Comparator\CompositeComparator;
use Skyline\Comparator\NaturalComparator;
use Skyline\Comparator\PropertyComparator;
use Skyline\Comparator\ReverseComparator;


class Person {
	protected $firstName;
	protected $lastName;
	public function __construct($firstName, $lastName) {
		$this->firstName = $firstName;
		$this->lastName = $lastName;
	}
	public function getFirstName() {
		return $this->firstName;
	}
	public function getLastName() {
		return $this->lastName;
	}
	public function getName() {
		return $this->firstName . " " . $this->lastName;
	}
}

$people[] = new Person('Ian', 'Unruh');
$people[] = new Person('Alyson', 'Bressie');

$c = new CompositeComparator();
$c->addComparator(new PropertyComparator('lastName', new NaturalComparator()));
$c->addComparator(new PropertyComparator('firstName', new NaturalComparator()));

usort($people, array($c, 'compare'));

foreach($people as $person) {
	echo $person->getName() . "\n";
}